package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.ProductSku;
import com.shop.result.ResultVO;
import com.shop.service.ProductSkuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/productSku")
public class ProductSkuController extends BaseController {
    private final ProductSkuService productSkuService;

    @GetMapping("/listProductSku")
    public ResultVO<Object> listProductSku(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        PageInfo<ProductSku> pageInfo = productSkuService.listProductSku(page, limit);
        return success(pageInfo);
    }

    @GetMapping("/listWithProductSku")
    public ResultVO<Object> listWithProductSku(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        PageInfo<ProductSku> pageInfo = productSkuService.listWithProductSku(page, limit);
        return success(pageInfo);
    }

    @GetMapping("/getProductSkuById")
    public ResultVO<Object> getProductSkuById(@RequestParam("id") Integer id) {
        ProductSku productSku = productSkuService.listProductSkuByProductId(id);
        return success(productSku);
    }
    @PostMapping("/addProductSku")
    public ResultVO<Object> addProductSku(@RequestBody ProductSku productSku) {
        productSkuService.addProductSku(productSku);
        return success();
    }
    @GetMapping("/deleteProductSku")
    public ResultVO<Object> deleteProductSku(@RequestParam("id") Integer id) {
        productSkuService.deleteProductSku(id);
        return success();
    }
    @GetMapping("/updateProductSku")
    public ResultVO<Object> updateProductSku(@RequestParam("id") Integer id, @RequestParam("skuCode") String skuCode, @RequestParam("price") double price, @RequestParam("stock") int stock) {
        productSkuService.updateProductSku(id, skuCode, price, stock);
        return success();
    }
    @GetMapping("/countProductSku")
    public ResultVO<Object> getTotal() {
        int total = productSkuService.getTotal();
        return success(total);
    }
}
